<template>
	<view class="flex-col homepage">
		<view class="flex-col wrapper">
			<view class="flex-row wraper-row">
				<view class="box"></view>
				<view class="u-line-1 text">车辆信息</view>
				<view class="u-line-1 text-two" @click="mouthCard()">购买月卡</view>
			</view>
			<view class="wraper-row-two">
				<view class="u-line-1 text-three">
          <input v-model="car.vehicleNumber" border="none" placeholder="请输入车牌号"/>
        </view>
				<view class="u-line-1 text-four">车牌号</view>
			</view>
			<view class="flex-row wraper-row-three">
				<view class="u-line-1 text-five">车辆品牌</view>
				<view class="u-line-1 text-six">
          <input v-model="car.vehicleBrand" border="none" placeholder="请输入车辆品牌"/>
        </view>
        
			</view>
			<view class="flex-row wraper-row-four">
				<view class="u-line-1 text-seven">车辆型号</view>
				<view class="u-line-1 text-eight">
          <input v-model="car.vehicleModel" border="none" placeholder="请输入车辆型号"/>
        </view>
			</view>
			<view class="wraper-row-five">
				<view class="u-line-1 text-nine">
        <input v-model="car.vehicleColor" border="none" placeholder="请输入车辆颜色"/></view>
				<view class="u-line-1 text-ten">颜色</view>
			</view>
			<view class="u-line-1 text-eleven">车辆图片</view>
      <image :src="fileUrl" style="width:300px;height: 200px;"></image>
			<u-upload class="upload" :width="600" :height="200" :fileList="fileList1" @afterRead="afterRead"
				@delete="deletePic" name="1" multiple :maxCount="10"></u-upload>
		</view>
		<view class="flex-row wrapper-two">
			<u-button class="button" type="error" size="medium" @click="updCar()">
				修改
			</u-button>
			<u-button class="button-two" @click="del()">
				删除
			</u-button>
		</view>
	</view>
</template>
<script>
  import request from '../../../request.js'
	export default {
		data() {
			return {
        carNumber:localStorage.getItem("vehicleNumber"),
        car:{},
        fileUrl:'',
        fileList1:[],
      }
		},
    onLoad(){
      this.getOneCar()
      
    },
		methods: {
      mouthCard(){
        uni.navigateTo({
          url:'./Vehiclemonthlycard'
        })
      },
      //修改
      updCar(){
        console.log("22")
        request({
        	url: `/carshop/vehicle-car/updCar`,
          data:this.car,
        	method: 'POST',
        	success: (res) => {
            this.updCarPhoto()
        	}
        })
      },
      updCarPhoto(){
        request({
        	url: `/systemuser/file/updCarPhoto`,
          data:{
            associatedId:this.car.vehicleCarId,
            fileUrl:this.fileUrl
          },
        	method: 'POST',
        	success: (res) => {
            console.log("成功")
        	}
        })
      },
      
      
      
      //查询图片
      getCarPhoto(){
        request({
        	url: `/systemuser/file/getCarPhoto/${this.car.vehicleCarId}`,
        	method: 'POST',
        	success: (res) => {
            console.log(res.data.data.file)
        		this.fileUrl=res.data.data.file.fileUrl
        	}
        })
      },
      //获取车辆
      getOneCar(){
        request({
        	url: `/carshop/vehicle-car/getOneCar/${this.carNumber}`,
        	method: 'POST',
        	success: (res) => {
        		console.log(res.data.data.car)
        		this.car=res.data.data.car
            this.getCarPhoto()
        	}
        })
      },
      // 删除图片
      deletePic(event) {
      	this[`fileList${event.name}`].splice(event.index, 1)
      },
      // 新增图片
      async afterRead(event) {
      	// 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
      	let lists = [].concat(event.file)
      	let fileListLen = this[`fileList${event.name}`].length
      	lists.map((item) => {
      		this[`fileList${event.name}`].push({
      			...item,
      			status: 'uploading',
      			message: '上传中'
      		})
      	})
      	for (let i = 0; i < lists.length; i++) {
      		const result = await this.uploadFilePromise(lists[i].url)
      		let item = this[`fileList${event.name}`][fileListLen]
      		this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
      			status: 'success',
      			message: '',
      			url: result
      		}))
      		fileListLen++
      	}
      },
      
      uploadFilePromise(url) {
      
      	return new Promise((resolve, reject) => {
      		let a = uni.uploadFile({
      			url: 'http://localhost/systemuser/file/upload', // 仅为示例，非真实的接口地址
      			filePath: url,
      			name: 'file',
      			formData: {
      				user: 'test'
      			},
      			success: (res) => {
      				this.fileUrl=res.data
      				console.log(this.fileUrl)
      				setTimeout(() => {
      					resolve(res.data.data)
      				}, 1000)
      			}
      		});
      	})
      },
		}
	}
</script>
<style lang="scss" scoped>
	/** 全局样式-开始,建议放在公共css样式文件中,比如common.css 或app.vue文件 */

	html,
	body {
		margin: 0;
		width: 100%;
		height: 100%;
		font-size: 16px
	}

	view,
	text,
	image {
		position: relative;
		box-sizing: border-box;
		flex-shrink: 0;
	}

	.flex-col {
		display: flex;
		align-items: flex-start;
		flex-direction: column;
	}

	.flex-row {
		display: flex;
		align-items: flex-start;
	}

	.flex-col .flex-row {
		width: 100%
	}

	/** 全局样式-结束*/

	.homepage {
		padding: 50rpx 0rpx 52rpx 28rpx;

		.wrapper {
			width: 702rpx;
			margin: 0rpx 0rpx 260rpx 4rpx;
			padding: 34rpx 0rpx 42rpx 27rpx;
			border-width: 2rpx;
			border-style: solid;
			border-color: rgba(221, 221, 221, 1);

			.wraper-row {
				width: 647rpx;
				margin-bottom: 22rpx;

				.box {
					width: 16rpx;
					height: 34rpx;
					margin: 6rpx 20rpx 0rpx 0rpx;
					border-radius: 100rpx;
					background: rgba(11, 84, 242, 1);
				}

				.text {
					width: 218rpx;
					margin-right: 260rpx;
					font-size: 32rpx;
					font-weight: 600;
					color: rgba(130, 130, 130, 1);
				}

				.text-two {
					width: 132rpx;
					height: 36rpx;
					font-size: 30rpx;
					font-weight: 700;
					color: rgba(93, 139, 255, 1);
				}
			}

			.wraper-row-two {
				width: 640rpx;
				padding: 49rpx 0rpx 31rpx 149rpx;
				border-top-color: rgba(226, 226, 226, 1);
				border-bottom-color: rgba(226, 226, 226, 1);

				.text-three {
					width: 194rpx;
					font-size: 30rpx;
					font-weight: 600;
					color: rgba(85, 85, 85, 1);
				}

				.text-four {
					width: 134rpx;
					bottom: 36rpx;
					left: 0rpx;
					font-size: 28rpx;
					position: absolute;
					font-weight: 700;
					color: rgba(173, 173, 173, 1);
				}
			}

			.wraper-row-three {
				width: 640rpx;
				justify-content: space-between;
				padding: 38rpx 287rpx 38rpx 0rpx;
				border-top-width: 2rpx;
				border-top-style: solid;
				border-top-color: rgba(226, 226, 226, 1);
				border-bottom-width: 2rpx;
				border-bottom-style: solid;
				border-bottom-color: rgba(226, 226, 226, 1);

				.text-five {
					width: 134rpx;
					font-size: 28rpx;
					font-weight: 700;
					color: rgba(173, 173, 173, 1);
				}

				.text-six {
					width: 194rpx;
					font-size: 30rpx;
					font-weight: 600;
					color: rgba(85, 85, 85, 1);
				}
			}

			.wraper-row-four {
				width: 640rpx;
				justify-content: space-between;
				padding: 39rpx 298rpx 39rpx 0rpx;
				border-top-color: rgba(226, 226, 226, 1);
				border-bottom-width: 2rpx;
				border-bottom-style: solid;
				border-bottom-color: rgba(226, 226, 226, 1);

				.text-seven {
					width: 134rpx;
					font-size: 28rpx;
					font-weight: 700;
					color: rgba(173, 173, 173, 1);
				}

				.text-eight {
					width: 194rpx;
					font-size: 30rpx;
					font-weight: 600;
					color: rgba(85, 85, 85, 1);
				}
			}

			.wraper-row-five {
				width: 640rpx;
				margin-bottom: 28rpx;
				padding: 35rpx 0rpx 43rpx 154rpx;
				border-top-color: rgba(226, 226, 226, 1);
				border-bottom-width: 2rpx;
				border-bottom-style: solid;
				border-bottom-color: rgba(226, 226, 226, 1);

				.text-nine {
					width: 194rpx;
					font-size: 30rpx;
					font-weight: 600;
					color: rgba(85, 85, 85, 1);
				}

				.text-ten {
					width: 134rpx;
					top: 32rpx;
					left: -2rpx;
					font-size: 28rpx;
					position: absolute;
					font-weight: 700;
					color: rgba(173, 173, 173, 1);
				}
			}

			.text-eleven {
				width: 158rpx;
				height: 34rpx;
				margin-bottom: 26rpx;
				font-size: 30rpx;
				font-weight: 600;
				color: rgba(180, 180, 180, 1);
			}

			.wraper-row-six {
				width: 628rpx;
				height: 286rpx;
				margin: 0rpx 0rpx 12rpx 6rpx;
				border-width: 2rpx;
				border-style: solid;
			}

			.wraper-row-seven {
				width: 628rpx;
				height: 286rpx;
				margin-left: 6rpx;
				border-width: 2rpx;
				border-style: solid;
			}
		}

		.wrapper-two {
			width: 706rpx;
			justify-content: space-between;

			.button {
				width: 340rpx;
				height: 78rpx;
				background: rgba(64, 99, 255, 1);
				border:none
			}

			.button-two {
				width: 340rpx;
				height: 78rpx;
				color: rgba(255, 28, 28, 1);
				border:1px red solid;
			}
		}
	}
</style>